//package com.vast.admin.controller;
//
//
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.vast.admin.annotation.CurrentManager;
//import com.vast.admin.annotation.UseToken;
//import com.vast.common.core.domain.entity.SysUser;
//import com.vast.common.core.domain.entity.SysRole;
//import com.vast.admin.entity.enums.QueryOrderEnum;
//import com.vast.admin.service.DeptService;
//import com.vast.admin.service.ManagerRoleService;
//import com.vast.admin.service.ISysUserService;
//import com.vast.admin.service.RoleService;
//import com.vast.common.annotation.Log;
//import com.vast.common.core.domain.AjaxResult;
//import com.vast.common.constant.MessageCode;
//import com.vast.common.core.domain.Result;
//import com.vast.system.core.constant.UserConstants;
//import com.vast.system.core.controller.BaseController;
//import com.vast.system.exception.BusinessException;
//import com.vast.system.shiro.ShiroUtils;
//import com.vast.system.utils.StringUtils;
//import io.swagger.annotations.*;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.List;
//import java.util.stream.Collectors;
//
///**
// * <p>
// * 管理员 前端控制器
// * </p>
// *
// * @author zhaohao
// * @since 2019-10-30
// */
//@RestController
//@Api(value = "用户相关接口", tags = { "用户模块" })
//@RequestMapping("/manager/admin")
//public class ManagerController extends BaseController {
//
//	@Autowired
//	private DeptService deptService;
//
//	@Autowired
//	private ISysRoleService roleService;
//
//	@Autowired
//	private ManagerRoleService managerRoleService;
//
//	@ApiOperation(value = "查询列表信息", notes = "通过条件查询列表")
//	@ApiImplicitParams({
//			@ApiImplicitParam(paramType = "query", name = "size", value = "分页条数", dataType = "int", defaultValue = "10", required = false),
//			@ApiImplicitParam(paramType = "query", name = "current", value = "页码,起始值:1", dataType = "int", defaultValue = "1", required = false),
//			@ApiImplicitParam(paramType = "query", name = "listMode", value = "是否集合模式:true不进行分页直接返回所有结果集", dataType = "boolean", defaultValue = "false", required = false),
//			@ApiImplicitParam(paramType = "query", name = "queryItems", value = "查询条件,json集合", defaultValue = "account,EQ,13419519796;", dataType = "String", required = false),
//			@ApiImplicitParam(paramType = "query", name = "orderField", value = "排序字段,多个','分隔", defaultValue = "create_time", dataType = "String",  required = false),
//			@ApiImplicitParam(paramType = "query", name = "order", value = "排序类型: ASC/DESC", dataType = "QueryOrderEnum",  required = false)
//	})
////	@Log(title = "查询列表信息")  //这里添加了AOP的自定义注解
//	@GetMapping("/page")
//	public Result<IPage<SysUser>> page(@ApiParam(hidden = true)@CurrentManager SysUser manager, @ApiParam(hidden = true) Page<SysUser> page, boolean listMode, String queryItems, String orderField, QueryOrderEnum order) {
//		return new Result<IPage<SysUser>>(MessageCode.SUCCESS, "获取成功", managerService.queryList(manager,page, listMode, queryItems, orderField,order));
//
//	}
//
//	@Autowired
//	private ISysUserService managerService;
//
//	// 获取管理员信息
//
//	@ApiOperation(value = "通过token获取管理员信息", notes = "获取管理员信息")
//	@ApiImplicitParams({
//			@ApiImplicitParam(paramType = "header", name = "token", value = "登录获取的token", dataType = "String", required = true)})
//	@GetMapping("/getManagerInfo")
//	@UseToken
//	public Result<SysUser> getManagerInfo(@ApiParam(hidden = true) @CurrentManager SysUser manager) {
//		return new Result(MessageCode.SUCCESS, "获取成功", manager);
//	}
//
//
//	@ApiOperation(value = "添加或更新用户信息", notes = "添加或更新用户信息")
//	@UseToken
//	@Log(title = "添加或更新用户信息")
//	@PostMapping("/addOrUpdate")
//	public Result<SysUser> addOrUpdate(@ApiParam(hidden = true)@CurrentManager SysUser manager, @RequestBody @ApiParam(name="SysUser",value="Manager信息",required=true) SysUser newManager) {
//		if(newManager != null && newManager.getDeptId() != null) {
//			boolean flag  = managerService.addOrUpdate(manager, newManager);
//			if(flag){
//				return new Result<SysUser>(MessageCode.SUCCESS, "添加成功", newManager);
//			}else{
//				return new Result<SysUser>(MessageCode.ERROR, "添加失败");
//			}
//		}else {
//			return new Result<SysUser>(MessageCode.PARAM_ERROR, "参数错误");
//		}
//	}
//
//
//	@ApiOperation(value = "删除管理员", notes = "删除管理员")
//	@UseToken
//	@Log(title = "删除管理员")
//	@DeleteMapping("/delete")
//	public Result<Boolean> delete(@ApiParam(hidden = true)@CurrentManager SysUser manager, @RequestBody @ApiParam(name="ids",value="数据id数组,以','分隔",required=true) Long[] ids) {
//		if(ids != null) {
//			boolean flag  = managerService.delete(manager, ids);
//			if(flag){
//				return new Result<Boolean>(MessageCode.SUCCESS, "删除成功");
//			}else{
//				return new Result<Boolean>(MessageCode.ERROR, "删除失败");
//			}
//		}else {
//			return new Result<Boolean>(MessageCode.PARAM_ERROR, "参数错误");
//		}
//	}
//
//	/**
//	 * 删除用户
//	 */
//	@DeleteMapping("/delete/{userIds}")
//	public AjaxResult remove(@PathVariable Long[] userIds)
//	{
//		return toAjax(managerService.deleteUserByIds(userIds));
//	}
//
//
//	// 获取管理员信息
//	@ApiOperation(value = "通过id获取管理员信息", notes = "获取管理员信息")
//	@ApiImplicitParams({
//			@ApiImplicitParam(paramType = "header", name = "token", value = "登录获取的token", dataType = "String", required = true)})
//	@GetMapping("/info/{id}")
//	@Log(title = "获取管理员信息")
//	@UseToken
//	public Result<SysUser> info(@ApiParam(hidden = true) @CurrentManager SysUser manager,@PathVariable("id") Long id) {
//		if(id != null && id.longValue() > 0){
//			SysUser managerInfo = managerService.info(manager,id);
//			if(managerInfo != null){
//				return new Result<SysUser>(MessageCode.SUCCESS, "获取成功", managerInfo);
//			}else{
//				return new Result<SysUser>(MessageCode.ERROR, "获取失败");
//			}
//		}
//		return new Result<SysUser>(MessageCode.PARAM_ERROR, "id不能为空");
//	}
//
//	@ApiOperation(value = "启/禁用用户", notes = "启/禁用用户")
//	@ApiImplicitParams({
//			@ApiImplicitParam(paramType = "query", name = "id", value = "数据id", dataType = "Long", required = true),
//			@ApiImplicitParam(paramType = "query", name = "status", value = "状态0-禁用 1-启用", dataType = "Integer", defaultValue="1", required = true)
//	})
//	@UseToken
//	@Log(title = "启/禁用用户")
//	@PostMapping("/enable")
//	public Result enable(@ApiParam(hidden = true)@CurrentManager SysUser manager, Long id, String status) {
//		SysUser bean = managerService.getById(id);
//		if(bean != null){
//			bean.setStatus(status);
//			managerService.saveOrUpdate(bean);
//			return new Result(MessageCode.SUCCESS, "修改成功",true);
//		}else{
//			return new Result(MessageCode.ERROR, "此数据不存在");
//		}
//
//	}
//
//	/**
//	 * 修改登录用户密码
//	 */
//
//	@ApiOperation(value = "修改密码", notes = "修改密码")
//	@ApiImplicitParams({
//			@ApiImplicitParam(paramType = "query", name = "password", value = "原始密码", dataType = "String",  required = true),
//			@ApiImplicitParam(paramType = "query", name = "newPassword", value = "新密码", dataType = "String",   required = true)
//	})
//    @PostMapping("/resetPassword")
//	@UseToken
//	public Result resetPassword(String password, String newPassword){
//		if(StringUtils.isEmpty(newPassword)){
//			return new Result<SysUser>(MessageCode.PARAM_ERROR, "新密码不为能空");
//		}
//		//原密码
//		password = ShiroUtils.sha256(password, ShiroUtils.getUserEntity().getSalt());
//		//新密码
//		newPassword = ShiroUtils.sha256(newPassword, ShiroUtils.getUserEntity().getSalt());
//
//		//更新密码
//		boolean flag = managerService.updatePassword(ShiroUtils.getUserEntity().getId(), password, newPassword);
//		if(!flag){
//			return new Result<SysUser>(MessageCode.PARAM_ERROR, "原密码不正确");
//		}
//		return new Result<SysUser>(MessageCode.SUCCESS, "修改成功");
//	}
//
//
//	/**
//	 * 重置密码
//	 */
//	@PutMapping("/resetPwd")
//	public AjaxResult resetPwd(@ApiParam(hidden = true)@CurrentManager SysUser manager, @RequestBody SysUser user)
//	{
//		managerService.checkUserAllowed(user);
//		SysUser modifyManager = managerService.getById(user.getId());
//		if(modifyManager == null){
//			throw  new BusinessException(MessageCode.ERROR, "账号不存在");
//		}
//		user.setPassword(ShiroUtils.sha256(user.getPassword(), modifyManager.getSalt()));
//		user.setUpdateBy(manager.getUserId());
//		return toAjax(managerService.resetPwd(user));
//	}
//
//
//	/**
//	 * 获取用户列表
//	 */
//	@ApiOperation(value = "查询列表", notes = "查询列表")
//	@GetMapping("/list")
//	public Result<IPage<SysUser>> list( @ApiParam(hidden = true) Page<SysUser> page, SysUser manager)
//	{
////		startPage();
//		IPage<SysUser> list = managerService.selectManagerList(page, manager);
//		for (SysUser mag : list.getRecords()) {
//			mag.setDept(deptService.getById(mag.getDeptId()));
//			mag.setRoles(managerRoleService.selectRolesByManagerId(mag.getId()));
//		}
//		return new Result<IPage<SysUser>>(MessageCode.SUCCESS, "获取成功",list);
//	}
//
//
//	/**
//	 * 新增用户
//	 */
//	@PostMapping
//	public AjaxResult add(@Validated @RequestBody SysUser user)
//	{
//		if (UserConstants.NOT_UNIQUE.equals(managerService.checkAccountUnique(user.getAccount())))
//		{
//			return AjaxResult.error("新增用户'" + user.getName() + "'失败，登录账号已存在");
//		}
//		else if (UserConstants.NOT_UNIQUE.equals(managerService.checkPhoneUnique(user)))
//		{
//			return AjaxResult.error("新增用户'" + user.getName() + "'失败，手机号码已存在");
//		}
////		user.setCreateBy(SecurityUtils.);
////		user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
//		return toAjax(managerService.save(user)?1:0);
//	}
//
//
//	/**
//	 * 根据用户编号获取详细信息
//	 */
//	@GetMapping(value = { "/", "/{userId}" })
//	public AjaxResult getInfo(@ApiParam(hidden = true)@CurrentManager SysUser manager, @PathVariable(value = "userId", required = false) Long userId)
//	{
//		long roleId = manager.getRoleIdList()[0];
//		SysRole role = roleService.getById(roleId);
//		AjaxResult ajax = AjaxResult.success();
//		List<SysRole> roles = roleService.selectRoleAll(role.getSort());
//		ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
////		ajax.put("posts", postService.selectPostAll());
//		if (StringUtils.isNotNull(userId))
//		{
//			ajax.put(AjaxResult.DATA_TAG, managerService.getById(userId));
////			ajax.put("postIds", postService.selectPostListByUserId(userId));
//			ajax.put("roleIds", roleService.selectRoleListByUserId(userId));
//		}
//		return ajax;
//	}
//
//}
